define("@wsb/guac-widget-shared/lib/common/ols-core/core-bundle-1a1a60ef.js",["exports","~/c/ScrollWidgetConstants","~/c/OlsConfigStore"],(function(t,e,r){"use strict";let n={strip_insignificant_zeros:!1,pattern:"[\\d\\,]*(\\.[\\d\\,]+)?",precision:3,thousands_separator:",",significant:!1,decimal_mark:"."},o={symbol_first:!0,with_currency:!1,currency:"USD",pattern:"[\\d\\,]*(\\.[\\d\\,]+)?",symbol:"$",precision:2,thousands_separator:",",decimal_mark:"."},s={symbol_first:!1,pattern:"[\\d\\,]*(\\.[\\d\\,]+)?",symbol:"%",precision:2,thousands_separator:",",decimal_mark:"."};const a={getNumberFormat:function(){return n},setNumberFormat:function(t){n=(global._||guac.lodash).assign({},n,t)},getCurrencyFormat:function(){return o},setCurrencyFormat:function(t){o=(global._||guac.lodash).assign({},o,t)},getPercentageFormat:function(){return s},setPercentageFormat:function(t){s=(global._||guac.lodash).assign({},s,t)},toNumber:function(t,e){if("string"!=typeof t||""===t)return t;var r=new RegExp(("."===this.getNumberFormat().thousands_separator?"\\":"")+this.getNumberFormat().thousands_separator,"g");const n=t.replace(r,"").replace(this.getNumberFormat().decimal_mark,".").replace(/ /g,"");return isNaN(n)?n:e?~~+n:+n},toFormattedNumber:function(t,e,r,n){if("number"!=typeof t)return t;let o=!1;t<0&&(o=!0);let s=t.toString().replace("-","").split(".");n="number"==typeof n?n:this.getCurrencyFormat().precision;const a=s[0].length+n;s=Number(parseFloat(t).toPrecision(a)).toString().replace("-","").split(".");let i="";for(let t=s[0].length-1,e=0;t>=0;t--,e++)3===e&&(i+=this.getNumberFormat().thousands_separator,e=0),i+=s[0][t];if(i=(o?"-":"")+i.split("").reverse().join(""),1===s.length&&!e||0===n)return i;if(1===s.length&&e){let t="";for(let e=0;e{const e={};for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)){const n=t[r];"object"==typeof n&&n.length?n.forEach((t=>{e[t]=r})):e[n]=r}return e},f=p(g),C=p(_),R={},O=["page","olsPageNum"],m=["sortOption","olsSortOption"],S=["keywords","olsKeywords"],E=[...O,...m,...S];function T(t,e,r){if(!t||!e)return null;const n=new RegExp("(?:[?|&]("+e+"=([a-z0-9-_/+%\\s'\"]+)))","i"),o=t.match(n);return o&&o.length>1?r?o[1]:o[2]:null}R[e.a.PRODUCT_LISTING]=[...O,...m],R[e.a.SEARCH_RESULTS]=[...O,...m,...S];var y=new class{constructor(){this.path="/",this.currentPageRoute=null;const t=this;"undefined"!=typeof window&&window.addEventListener("popstate",(function(e){const r=e.state&&e.state.view,n=e.state&&e.state.params;r?t.dispatchView(r,n):t.parseQueryString(window.location.search)}))}init(t,e,r){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;this.path=t||"/",this.currentPageRoute=o;const s=-1!==t.indexOf("ols/")?t.substring(t.lastIndexOf("ols/")):"";n.initialOlsPath=s,this.parseQueryString(e,r,n)}resolveRoute(t,e){let r=(this.useFriendlyRouting?_:g)[t];return"object"==typeof r&&r.length&&(r=r[e.taxonPermalink?1:0],e.routePath===this.ALL_PRODUCTS_ROUTE&&(r=this.ALL_PRODUCTS_ROUTE)),r}dispatchView(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!r.O.isProvisioned())return;const o=n.olsSortOption||n.sortOption,s=n.olsKeywords||n.keywords,a=n.olsPageNum||n.page;let c=n.taxonPermalink;const u=n.routePath;if(t&&n.slug&&t===e.a.PRODUCT_DETAIL){const{slug:t,selectedVariantSku:r}=n;e.P.setProductDetailData({slug:t,selectedVariantSku:r}),e.P.loadProduct()}else t&&t===e.a.PRODUCT_LISTING?(u===this.ALL_PRODUCTS_ROUTE||c||(c=r.O.getDefaultCategory()),e.P.loadProducts({page:a,taxonPermalink:c,sortOption:o,routePath:u})):t&&s&&t===e.a.SEARCH_RESULTS?e.P.loadProducts({page:a,taxonPermalink:c,searchKeywords:s,sortOption:o,routePath:u}):i.setView(t)}get useFriendlyRouting(){return null!==this.currentPageRoute}generateUrl(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=e.q.parse(location.search),o=this.resolveRoute(t,r);let s,a=o,i="";switch(t){case e.a.PRODUCT_DETAIL:r.selectedVariantSku&&(i=`/v/${encodeURIComponent(r.selectedVariantSku)}`),a=o.replace(":slug",`${r.slug}${i}`);break;case e.a.PRODUCT_LISTING:r.taxonPermalink&&(a=o.replace(":taxonPermalink",r.taxonPermalink))}if(E.forEach((t=>{t in n&&delete n[t]})),r){(R[t]||[]).forEach((t=>{Object.prototype.hasOwnProperty.call(r,t)&&(n[t]=r[t])}))}const c=t=>t&&Object.keys(t).length?`?${e.q.stringify(t)}`:"";return this.useFriendlyRouting?(delete n.olsPage,s=`${this.currentPageRoute}/${a}${c(n)}`):(n.olsPage=a,s=`${this.path}${c(n)}`),s=s.replace(/\/\//g,"/"),s}setPath(t){this.path=t||"/"}testRoutePath(t,e){if(-1===t.indexOf("/"))return t.toLowerCase()===e.toLowerCase();const r=t.replace(/\:[a-z0-9]+/gi,"[^?]+");return new RegExp(r,"ig").test(e)}normalizeRoutePath(t){switch(t){case d:case h:return this.ALL_PRODUCTS_ROUTE;case u:case l:return this.PRODUCTS_ROUTE;default:return t}}parseQueryString(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};t&&(t=decodeURIComponent(t));const n=T(t,c)||"";let o=null,s=null;if(n||this.useFriendlyRouting){const t=n?f:C,e=n||r.initialOlsPath,a=Object.keys(t);for(let r=0;r{0===t.indexOf(":")&&(a[t.substring(1)]=s[e])}))}if(i&&i.length){const t=this.useFriendlyRouting?4:3;u[t]&&(a.selectedVariantSku=decodeURIComponent(u[t]))}let l=t||"";if((R[s]||[]).forEach((t=>{const e=T(l,t,!0);e&&(a[t]=T(l,t),l=l.replace("&"+e,""))})),s){const t=this.useFriendlyRouting&&!r.initialOlsPath&&!n;this.navigate(s,a,!0,t)}}navigate(t,e,r,n){const{keywords:o,sortOption:s}=e||{};o||"descend_by_match"!==s||delete e.sortOption,this.dispatchView(t,e),"undefined"==typeof window||n||this.rewriteURL({replaceState:r,view:t,params:e})}rewriteURL(t){let{replaceState:e,view:r,params:n}=t;const o=e?"replaceState":"pushState",s={view:r};n&&(s.params=n);const a=this.generateUrl(r,n);window.history[o](s,document.title,a)}get PRODUCTS_ROUTE(){return this.useFriendlyRouting?l:u}get ALL_PRODUCTS_ROUTE(){return this.useFriendlyRouting?h:d}};class A extends r.E{constructor(){super(...arguments),this.state={fetching:!1,processing:!1,error:null,errorRetryable:!1,order:null,cart:null,validCoupon:null},this.register()}setState(t){(global._||guac.lodash).assign(this.state,t),this.emit("change")}getOrder(){const{order:t}=this.state;return t}isProcessing(){const{processing:t}=this.state;return t}getCart(){const{cart:t}=this.state;return t}getState(){return this.state}register(){this.dispatchToken=r.A.register((t=>{const{action:r}=t,{data:n}=r,o={fetching:!1,processing:!0,error:null,errorRetryable:!1};switch(r.type){case e.C.CART_LOAD:case e.C.CART_CREATE:this.setState({fetching:!0,error:null,errorRetryable:!1});break;case e.C.CART_WAS_LOADED:this.setState({fetching:!1,cart:n,order:{number:n.number,token:n.token}});break;case e.C.NO_CART_WAS_LOADED:this.setState({fetching:!1,cart:null,order:null});break;case e.C.CART_ITEM_MODIFY:this.setState({...o,cart:(s=this.state.cart,a=n,a.forEach((t=>{const e=(global._||guac.lodash).find(s.line_items,(e=>e.id===+t.id));e&&(e.quantity=t.quantity)})),s)});break;case e.C.CART_ITEM_ADD:case e.C.CART_ITEM_REMOVE:this.setState(o);break;case e.C.CART_ITEM_WAS_ADDED:case e.C.ERROR_CART_ITEM_ADD:case e.C.CART_ITEM_WAS_MODIFIED:case e.C.CART_ITEM_WAS_REMOVED:this.setState({fetching:!1,processing:!1});break;case e.C.ERROR_CART_ITEM_REMOVE:case e.C.ERROR_CART_ITEM_MODIFY:this.setState({fetching:!1,processing:!1,error:r.error});break;case e.C.APPLY_COUPON:this.setState({fetching:!0,validCoupon:null});break;case e.C.COUPON_WAS_APPLIED:this.setState({fetching:!1,validCoupon:!0,cart:n});break;case e.C.COUPON_WAS_INVALID:this.setState({fetching:!1,validCoupon:!1,cart:n.response});break;case e.A.SESSION_STARTED:this.setState({error:null});break;case e.A.SESSION_FAILED:this.setState({error:r.error})}var s,a}))}}var P=new A;function w(t){const{fetching:n,processing:o}=P.getState();if(n||o)return;const s=e.g();null!==s?(r.d({type:e.C.CART_LOAD}),e.l(s,t).then((function(t){return k(t)})).catch((function(t){return U(t.error)}))):r.a({type:e.C.NO_CART_WAS_LOADED})}function D(){if(!P.getState().fetching)return r.d({type:e.C.CART_CREATE}),I()}function b(t,n,o,s,a){return e.b(t,n,o,s).then((function(){r.a({type:e.C.CART_ITEM_WAS_ADDED})})).then((function(){return!!a&&a()})).catch((function(t){return function(t,n){const{errors:o}=n;switch(t.status_code){case 403:return L();case 422:t.messages=o}r.a({type:e.C.ERROR_CART_ITEM_ADD,error:t})}(t.error,t.response)}))}function I(){return e.c().then((function(t){return k(t)})).catch((function(t){return U(t.error)}))}function L(){e.e();const{renderMode:t}=r.O.getState();"PUBLISH"!==t?window.location.reload():window.location=r.O.getStorePageUrl()}function k(t){const{state:n}=t;"complete"===n||"canceled"===n?(e.e(),r.a({type:e.C.NO_CART_WAS_LOADED})):(t.currency!==r.O.getCurrentCurrency()&&e.O.loadConfig(!0),e.s(t),r.a({type:e.C.CART_WAS_LOADED,data:t}))}function U(t){switch(t.status_code){case 404:case 401:I();break;case 403:return L();default:r.a({type:e.C.ERROR_CART_LOAD,error:t})}}function F(t){switch(t.status_code){case 403:return L();case 404:I()}r.a({type:e.C.ERROR_CART_ITEM_MODIFY,error:t})}var N={createCart:D,loadCart:w,addToCart:function(t,n,o,s){if(P.getState().processing)return;r.d({type:e.C.CART_ITEM_ADD});let a=P.getOrder();a?b(a,t,n,o,s):D().then((()=>(a=P.getOrder(),b(a,t,n,o,s))))},removeFromCart:function(t){if(P.getState().processing)return;r.d({type:e.C.CART_ITEM_REMOVE});const n=P.getOrder();e.r(n,t).then((function(){return r.a({type:e.C.CART_ITEM_WAS_REMOVED}),void w()})).catch((function(t){return function(t){if(t&&403===t.status_code)return L();r.a({type:e.C.ERROR_CART_ITEM_REMOVE,error:t}),w()}(t.error)}))},modifyCart:function(t){if(P.getState().processing)return;r.d({type:e.C.CART_ITEM_MODIFY,data:t});const n=P.getOrder();e.m(n,t).then((function(){return r.a({type:e.C.CART_ITEM_WAS_MODIFIED}),void w()})).catch((function(t){return F(t.error)}))},doCheckout:function(t){if(t&&t.length>0){if(P.getState().processing)return;r.d({type:e.C.CART_ITEM_MODIFY,data:t});const n=P.getOrder();e.m(n,t).then((function(){window.document.getElementById("DO_CHECKOUT_ID").submit()})).catch((function(t){return F(t.error)}))}else{window.document.getElementById("DO_CHECKOUT_ID").submit()}},applyCoupon:function(t){r.d({type:e.C.APPLY_COUPON});const n=P.getOrder();return e.d(n,t).then((function(t){return function(t){r.a({type:e.C.COUPON_WAS_APPLIED,data:t})}(t),{...t,valid:!0}})).catch((function(t){return function(t){r.a({type:e.C.COUPON_WAS_INVALID,data:t})}(t),{...t,valid:!1}}))}};var v={scrollShopWidget:function(){r.d({type:e.f.SCROLL_WIDGET,data:"shop"}),"undefined"!=typeof window&&window.dispatchEvent(new Event("shopScroll"))}};"undefined"!=typeof window&&(window.OLSCore={...window.OLSCore||{},RouteHandler:y,ScrollWidgetActions:v,ShopViewConstants:e.a}),t.OlsConfigActions=e.O,t.ShopViewConstants=e.a,t.OlsConfigStore=r.O,t.CartActions=N,t.CartStore=P,t.NumberFormatter=a,t.RouteHandler=y,t.ScrollWidgetActions=v,Object.defineProperty(t,"__esModule",{value:!0})})),"undefined"!=typeof window&&(window.global=window); //# sourceMappingURL=core-bundle-1a1a60ef.js.map